package com.weasel.weixin.mp.request;

import com.google.common.collect.ImmutableMap;
import com.weasel.http.HttpClientSecretary;
import com.weasel.http.adapter.TemplateReplaceResponseAdapter;
import com.weasel.weixin.commons.AccessTokenRequest;
import com.weasel.weixin.commons.CommonRequest;
import com.weasel.weixin.commons.config.CommonConfig;
import com.weasel.weixin.commons.config.CommonConsts;
import com.weasel.weixin.mp.config.MpConfig;
import com.weasel.weixin.mp.response.WeiXinServerIpListResponse;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
 * Created by Dylan on 2015/9/28.
 */
public class WeiXinServerIpListRequest extends CommonRequest{


    public WeiXinServerIpListRequest(CommonConfig config) {
        super(config);
    }

    public List<String> getIpList() throws IOException, ExecutionException {

        Map<String,String> params  = ImmutableMap.of("access_token",new AccessTokenRequest(config).getAccessToken());
        WeiXinServerIpListResponse response = HttpClientSecretary.get()
                                                                 .withURI(CommonConsts.IP_LIST_URL)
                                                                 .withParams(params)
                                                                 .doItWithJson(WeiXinServerIpListResponse.class, new TemplateReplaceResponseAdapter() {
                                                                     @Override
                                                                     public Map<String, String> getReplaceTemplate() {
                                                                         return ImmutableMap.of("ip_list","ipList");
                                                                     }
                                                                 });

        return response.getIpList();
    }
}
